package hu.mapro.flang.gwt.client;

import hu.mapro.flang.gwt.client.request.ApplicationRequestFactory;
import hu.mapro.flang.gwt.domain.client.AutoBeans.CreateFieldVisitor;
import hu.mapro.flang.gwt.domain.client.AutoBeans.RequestFactory;
import hu.mapro.gwtui.client.Display;
import hu.mapro.gwtui.client.HasPages;
import hu.mapro.gwtui.client.LoginInterface;
import hu.mapro.gwtui.client.Menu;
import hu.mapro.gwtui.client.MessageInterface;
import hu.mapro.gwtui.client.UserInterface;
import hu.mapro.gwtui.client.Window;
import hu.mapro.gwtui.client.impl.LoadingDisplay;
import hu.mapro.gwtui.client.login.DefaultLoginService;
import hu.mapro.gwtui.client.login.LoginService;
import hu.mapro.gwtui.gxt.client.GxtUserInterface;

import javax.inject.Singleton;

import com.google.gwt.core.client.GWT;
import com.google.gwt.inject.client.AbstractGinModule;
import com.google.inject.Provides;
import com.google.web.bindery.event.shared.SimpleEventBus;

public class ApplicationGinModule extends AbstractGinModule {
	protected void configure() {
		bind(Menu.class).to(UserInterface.class);
		bind(Window.class).to(UserInterface.class);
		bind(LoginInterface.class).to(UserInterface.class);
		bind(MessageInterface.class).to(UserInterface.class);
		bind(HasPages.class).to(UserInterface.class);
		
		bind(UserInterface.class).to(GxtUserInterface.class);
		
		bind(LoginService.class).to(DefaultLoginService.class);
		bind(Display.class).to(LoadingDisplay.class);
		
		bind(RequestFactory.class).to(ApplicationRequestFactory.class);
		
		bind(CreateFieldVisitor.class).to(hu.mapro.flang.gwt.client.ui.CreateFieldVisitor.class);
	}
	
	@Provides
	@Singleton
	public ApplicationRequestFactory createRequestFactory() {
		ApplicationRequestFactory rf = GWT.create(ApplicationRequestFactory.class);
		rf.initialize(new SimpleEventBus());
		return rf;
	}
}